<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>旋转</title>
    <script type="text/javascript">
        function load () {
            let c = document.getElementById('myCanvas');
            let context = c.getContext('2d');

            // 把坐标轴移到(x, y)
            context.translate(250, 250);

            for(let i=1; i<10; i++) {
                context.save();
                context.rotate(Math.PI*(1/2+i/4));
                context.translate(0, -150);
                // 线性缩放
                context.scale((1-0.08*i),(1-0.08*i));
                context.fillStyle='rgb(' + (30*i) + ',' + (255-30*i) + ',255)';
                context.fillRect(-30, -30, 60, 60);
                // context.fill();
                // 回到原点
                context.restore();
            }
        }

        window.onload  = function () {
            load();
        }
    </script>
</head>
<body>
    <canvas id="myCanvas" style="border: 1px solid #000000" width="800" height="450">
        你的浏览器不支持canvas元素！
    </canvas>
</body>
</html>